package com.scm.controller;

/**
 * @author CHL
 * @ClassName: ReportController
 * @Description: TODO
 * @date 2022/3/8 14:33
 * @Version 1.0
 */
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scm.dao.PayRecordMapper;
import com.scm.dao.PomainMapper;
import com.scm.dao.ProductMapper;
import com.scm.dao.SomainMapper;
import com.scm.dao.StockRecordMapper;
import com.scm.entity.Pomain;
import com.scm.entity.Somain;
import com.scm.service.IPomainService;
import com.scm.service.ISomainService;
import com.scm.service.IStockService;
import com.scm.util.StringUtil;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/main/report"})
public class ReportController
{
    private HashMap<String, Object> result = new HashMap();
    @Autowired
    private PomainMapper pomainMapper;
    @Autowired
    private SomainMapper somainMapper;
    @Autowired
    private IPomainService pomainService;
    @Autowired
    private ISomainService somainService;
    @Autowired
    private PayRecordMapper payRecordMapper;
    @Autowired
    private StockRecordMapper stockRecordMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private IStockService stockService;

    public boolean checkTime(String time)
    {
        if (StringUtil.isEmpty(time))
        {
            this.result.put("status", Integer.valueOf(3));
            this.result.put("statusInfo", "入参不能为空");
            return false;
        }
        if (!time.matches("^[1-9]\\d{3}-\\d{2}$"))
        {
            this.result.put("status", Integer.valueOf(3));
            this.result.put("statusInfo", "入参格式不正确");
            return false;
        }
        return true;
    }

    @RequestMapping({"/pomain/main"})
    public HashMap<String, Object> report_pomain(String time, Integer page)
    {
        if (!checkTime(time)) {
            return this.result;
        }
        this.result = this.pomainMapper.report(time);
        PageInfo<Pomain> list = this.pomainService.selectReport(Integer.valueOf(page == null ? 1 : page.intValue()), time);
        this.result.put("details", list);

        return this.result;
    }

    @RequestMapping({"/somain/main"})
    public HashMap<String, Object> report_somain(String time, Integer page)
    {
        if (!checkTime(time)) {
            return this.result;
        }
        this.result = this.somainMapper.report(time);
        PageInfo<Somain> list = this.somainService.selectReport(Integer.valueOf(page == null ? 1 : page.intValue()), time);
        this.result.put("details", list);

        return this.result;
    }

    @RequestMapping({"/payment/main"})
    public HashMap<String, Object> report_payment(String time, Integer page)
    {
        if (!checkTime(time)) {
            return this.result;
        }
        this.result = this.payRecordMapper.report(time);

        return this.result;
    }

    @RequestMapping({"/payment/detail/pay"})
    public PageInfo<HashMap<String, Object>> report_payment_pay(String time, Integer page)
    {
        PageHelper.startPage(page == null ? 1 : page.intValue(), 10);

        List<HashMap<String, Object>> payDetail = this.payRecordMapper.selectPayDetail(time);
        PageInfo<HashMap<String, Object>> info = new PageInfo(payDetail);
        return info;
    }

    @RequestMapping({"/payment/detail/receipt"})
    public PageInfo<HashMap<String, Object>> report_payment_rece(String time, Integer page)
    {
        PageHelper.startPage(page == null ? 1 : page.intValue(), 10);

        List<HashMap<String, Object>> payDetail = this.payRecordMapper.selectReceDetail(time);
        PageInfo<HashMap<String, Object>> info = new PageInfo(payDetail);
        return info;
    }

    @RequestMapping({"/instock/main"})
    public HashMap<String, Object> report_instock(String time, Integer page)
    {
        if (!checkTime(time)) {
            return this.result;
        }
        this.result = this.stockRecordMapper.selectInstockReport(time);
        PageInfo<HashMap<String, Object>> info = this.stockService.selectInstock(page, time);
        this.result.put("details", info);
        return this.result;
    }

    @RequestMapping({"/outstock/main"})
    public HashMap<String, Object> report_outstock(String time, Integer page)
    {
        if (!checkTime(time)) {
            return this.result;
        }
        this.result = this.stockRecordMapper.selectOutstockReport(time);
        PageInfo<HashMap<String, Object>> info = this.stockService.selectOutstock(page, time);
        this.result.put("details", info);

        return this.result;
    }

    @RequestMapping({"/stock/main"})
    public HashMap<String, Object> report_stock(String time, Integer page)
    {
        if (!checkTime(time)) {
            return this.result;
        }
        this.result = this.productMapper.selectTotalNum(time);
        PageInfo<HashMap<String, Object>> list = this.stockService.selectReport(Integer.valueOf(page == null ? 1 : page.intValue()), time);
        this.result.put("details", list);

        return this.result;
    }
}

